using System;
using System.Text;
using System.Collections.Generic;

namespace Framework.Core.Search
{
    public class SearchConditionCollection : LinkedList<ISearchCondition>
    {
        public string Expression
        {
            get
            {
                StringBuilder expression = new StringBuilder();
                IEnumerator<ISearchCondition> enumerator = this.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    expression.Append(enumerator.Current.Expression + " ");
                }
                return expression.ToString();
            }
        }

        public string Description
        {
            get
            {
                StringBuilder description = new StringBuilder();
                IEnumerator<ISearchCondition> enumerator = this.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    description.Append(enumerator.Current.Description + " ");
                }
                return description.ToString();
            }
        }
        
        public bool Contains(SearchCondition condition)
        {
            Enumerator enumerator = this.GetEnumerator();
            while (enumerator.MoveNext())
            {
                if (enumerator.Current.Equals(condition))
                {
                    return true;
                }
            }
            return false;
        }

        public void AddAfter(ISearchCondition beforeCondition, ISearchCondition condition)
        {
            LinkedListNode<ISearchCondition> beforeNode = this.Find(beforeCondition);
            this.AddAfter(beforeNode, condition);
        }
    }
}
